
{extend name="User/index" /}
{block name="users"}
<div class="col-xs-12" style="margin-top: 20px;">
    {if empty($result)}
    <center>
        <div class="col-xs-12" style="margin-top: 40px;">
            <a href="{:url('mobile/Index/index')}">还没有评论呦！看小片评论吧</a>
        </div>
    </center>
    {elseif !empty($result)}
    {foreach $result as $v}
    <div class="nav-movie col-xs-12" style="margin-bottom:15px;">
        <a href="{:url('mobile/Index/show', ['id'=>$v['id']])}">
            <img class="pull-left" src="../../../../../uploads/{$v.cover}" alt="" width="100">
            <div  class="pull-right  col-xs-8">
                <p class="col-xs-12">{$v.time}</p>
                <p class="col-xs-12" style="overflow:hidden;text-overflow:ellipsis;white-space:nowrap;">标题:{$v.title}</p>
            <p class="col-xs-12" style="overflow:hidden;text-overflow:ellipsis;white-space:nowrap;">内容:{$v.comment}</p>
            </div>
        </a>
        <button type="button" class="btn btn-info del-btn" data-id="{$v.hcid}" style="margin-left: 35px;">删除评论</button>
    </div>
    {/foreach}
    {/if}
</div>

<script>
        $(function(){
        // 触发删除用户
        $('.del-btn').click(function (){
            var ac_id = $(this).attr('data-id');
            if (confirm('你确定要删除吗?!')) {
            var obj = $(this).parent();
            var com = $('#com-num');
            // console.log(obj);
            delAjax(ac_id,obj,com);
        }
        });
        // AJAX删除
        function delAjax(id,obj,com){
            $.ajax({
            type: 'post',
            url: '/mobile/User/delete' ,
            data: {
                id:id
            },
            dataType: 'json',
            success: function (data) {
                    // 将该条目删除掉
                    obj.remove();
                    com.text(com.text()-1);
            },
            error: function () {
                alert('AJAX操作失败');
            }
        });
        }

        })
    </script>
{/block}

